<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/10/22
 * Time: 10:56
 */

namespace app\adminapiv3\service;


class ServerRandCode extends Base
{

    function createCaptcha()
    {
        $ip = $_SERVER['REMOTE_ADDR'];
        $condition['ip'] = $ip;
        $codeServer = new \app\common\service\ServerRandCode();
        $codeInfo = $codeServer->findData($condition);

        $code = createSalt(4);
        if($codeInfo){
            //修改
            $updateData['code'] = $code;

            $codeServer->modify(['id' => $codeInfo['id']], $updateData);
        }else{
            $addData['ip'] = $ip;
            $addData['code'] = $code;
            $addData['ctime'] = time();
            $codeServer->add($addData);
        }

        return $code;
    }
}